package br.com.peperoncino.model;

import javafx.scene.control.Label;
import javafx.scene.control.TextField;

public class FormValidation {

	public static boolean textFieldNotEmpty(TextField i){
		
		boolean r = false;
		
		if(i.getText() != null && !i.getText().isEmpty()){
			r = true;
		}
		
		return r;
	}
	
	public static boolean textFieldNotEmpty(TextField i, Label l, String aValidationText){
		
		boolean r = true;
		
		String c = null;
		i.getStyleClass().remove("error");
		
		if(!textFieldNotEmpty(i)){
			r = false;
			c = aValidationText;
			i.getStyleClass().add("error");
		}
		
		l.setText(c);
		
		return r;
	}
	
	public static boolean textFieldTypeDate(TextField i){
		
		boolean r = false;
		
		//dd/mm/yyyy
		                        
		if(i.getText().matches("(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\\d\\d")){
			r = true;
		}
		
		return r;
	}
	
	public static boolean textFieldTypeDate(TextField i, Label l, String aValidationText){
		
		boolean r = true;
		
		String c = null;
		i.getStyleClass().remove("error");
		
		if(!textFieldTypeDate(i)){
			r = false;
			c = aValidationText;
			i.getStyleClass().add("error");
		}
		
		l.setText(c);
		
		return r;
	}

	public static boolean textFieldTypeNumber(TextField i){
		
		boolean r = false;
		
		//dd/mm/yyyy
		if(i.getText().matches("([0-9]+)")){
			r = true;
		}
		
		return r;
	}
	
	public static boolean textFieldTypeNumber(TextField i, Label l, String aValidationText){
		
		boolean r = true;
		
		String c = null;
		i.getStyleClass().remove("error");
		
		if(!textFieldTypeNumber(i)){
			r = false;
			c = aValidationText;
			i.getStyleClass().add("error");
		}
		
		l.setText(c);
		
		return r;
	}
	
}
